/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"B7CB19C4-363A-4F9C-9D95-6A62DE23402C"}
 */
function onDataChangeCuit(oldValue, newValue, event) {

	var query 	= 'select proveedor_id, razon_social from proveedor where cuit = ? and es_fletero = 0'
	var args 	= [newValue]
	var max 	= 1
	
	var $ds 	= databaseManager.getDataSetByQuery('infocom',query,args,max)
	
	if ($ds.getMaxRowIndex() != 0)
	{
		globals.DIALOGS.showErrorDialog('Error',  'CUIT Duplicado: ' + $ds.getValue(1,2),  "OK")
		return false
	}
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"D48AE65C-4BD8-4B54-AD36-F9EBEB7B9AE6"}
 */
function iraResumenInteractivo(event) {
	globals.gProveedorDesde = proveedor_id
	globals.mostrarForm('resumen_1')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"3CDEB7CE-72CF-48B3-8DD5-632E27075D4F"}
 */
function eliminarContacto(event) {
	var $resp = globals.DIALOGS.showQuestionDialog('Confirmación','¿Está seguro que desea eliminar este contacto?','Si','No')
	if ($resp == 'Si')
		proveedor_to_contactos_pr.deleteRecord()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"A60FEC4B-6087-4F72-A847-FB819D1CC4C1"}
 */
function agregarContacto(event) {
	databaseManager.setAutoSave(false)
	proveedor_to_contactos_pr.newRecord()
	forms.contactos_pr_alta.controller.loadRecords(proveedor_to_contactos_pr)
	globals.formEnVentana('contactos_pr_alta','ALTA_CONTACTO','Alta de Contacto')
}
